package com.huawei.appmarket.service.store.awk.card;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Handler;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appgallery.foundation.card.base.card.BaseDistCard;
import com.huawei.appgallery.foundation.card.base.normal.bean.NormalCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse.Layout;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse.LayoutData;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.button.DownloadButton;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appmarket.framework.widget.ExpandableLayout;
import com.huawei.appmarket.service.store.awk.bean.BaseHorizontalCardBean;
import com.huawei.appmarket.service.store.awk.widget.horizon.BaseHorizonCard;
import com.huawei.hwid.core.constants.HwAccountConstants;
import huawei.widget.HwTextView;
import java.util.List;
import java.util.Locale;
import o.azb;
import o.cdr;
import o.cfv;
import o.cfw;
import o.cgz;
import o.chd;
import o.chi;
import o.chy;
import o.chz;
import o.cia;
import o.cib;
import o.cie;
import o.cig;
import o.cki;
import o.cvt;
import o.BaseRequest;
import o.dgm;
import o.djh;
import o.Logger;
import o.dni;
import o.dof;
import o.ContentManager;
import o.eib;
import o.eiu;
import o.epv;
import o.CollectCheck;
import o.eqx;
import o.eqz;
import o.erq;
import o.evx;
import o.ewm.d;
import o.ewm.i;
import o.ewm.j;

public class NormalCard extends BaseDistCard {
    private HwTextView ʻ;
    private HwTextView ʻॱ;
    private ImageView ʼ;
    protected TextView ʽ;
    private boolean ˊॱ = true;
    protected TextView ˋ;
    private chy ˋˋ;
    private LinearLayout ˋॱ;
    private chz ˋᐝ;
    private e ˌ;
    private cdr ˍ;
    private int ˎˎ;
    private int ˏˎ;
    private chd ˏˏ;
    private TextView ˏॱ;
    private BaseDetailResponse ˑ;
    private RelativeLayout ͺ;
    private ImageView ॱˊ;
    private View ॱˋ;
    private View ॱˎ;
    private ImageView ॱॱ;
    private ExpandableLayout ॱᐝ;
    protected View ᐝ;
    private cig ᐝॱ;

    class b implements Runnable {
        final /* synthetic */ NormalCard ˋ;

        private b(NormalCard normalCard) {
            this.ˋ = normalCard;
        }

        public void run() {
            ((BaseHorizonCard) this.ˋ.ˍ.ˎ(0)).ॱॱ().ˊ();
        }
    }

    class e implements IServerCallBack {
        final /* synthetic */ NormalCard ˋ;
        private cig ॱ;

        private e(NormalCard normalCard, cig o_cig) {
            this.ˋ = normalCard;
            this.ॱ = o_cig;
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            this.ˋ.ˏˏ = (chd) o_cvu;
            this.ˋ.ˑ = (BaseDetailResponse) responseBean;
            if (ˎ(this.ˋ.ˑ.ᐝॱ())) {
                Logger.e("NormalCard", "No data resources!");
                return;
            }
            this.ˋ.ॱᐝ.removeAllViews();
            this.ˋ.ॱᐝ.addView(this.ˋ.ˏ(this.ˋ.ॱᐝ));
            if (this.ˋ.ˊᐝ instanceof NormalCardBean) {
                ((NormalCardBean) this.ˋ.ˊᐝ).ॱ(this.ˋ.ˏˏ);
                ((NormalCardBean) this.ˋ.ˊᐝ).ˊ(this.ˋ.ˑ);
                ((NormalCardBean) this.ˋ.ˊᐝ).ˎ(false);
            }
            if (this.ॱ != null) {
                djh.ˎ().ˊ(((NormalCardBean) this.ˋ.ˊᐝ).ͺˏ());
                this.ॱ.ˋ();
            }
        }

        private boolean ˎ(List<LayoutData> list) {
            if (CollectCheck.isEmpty(list) || CollectCheck.isEmpty(((LayoutData) list.get(0)).ˋ()) || !(((LayoutData) list.get(0)).ˋ().get(0) instanceof BaseHorizontalCardBean) || CollectCheck.isEmpty(((BaseHorizontalCardBean) ((LayoutData) list.get(0)).ˋ().get(0)).ʻˋ()) || ((BaseHorizontalCardBean) ((LayoutData) list.get(0)).ˋ().get(0)).ʻˋ().size() < 3) {
                return true;
            }
            return false;
        }
    }

    public NormalCard(Context context) {
        super(context);
        if (context instanceof Activity) {
            this.ˏˎ = dgm.ˎ((Activity) context);
        }
    }

    public cgz ˏ(View view) {
        ˏ((ImageView) view.findViewById(j.ʻˊ));
        ˎ((ImageView) view.findViewById(j.ﾟ));
        ˊ((ImageView) view.findViewById(j.ꜞˋ));
        ॱ((TextView) view.findViewById(j.ʽ));
        ˊ((TextView) view.findViewById(j.ˋ));
        ˋ((DownloadButton) view.findViewById(j.ᵣ));
        this.ˏॱ = (TextView) view.findViewById(j.ㆍʼ);
        this.ˋ = (TextView) view.findViewById(j.ॱⵈ);
        this.ʼ = (ImageView) view.findViewById(j.ˎᵢ);
        this.ॱॱ = (ImageView) view.findViewById(j.ˏᵢ);
        this.ʻ = (HwTextView) view.findViewById(j.ˊᐝ);
        this.ॱˋ = view.findViewById(j.ᐝᐝ);
        this.ʻॱ = (HwTextView) view.findViewById(j.ꜟʽ);
        this.ˋॱ = (LinearLayout) view.findViewById(j.ˈʾ);
        this.ᐝ = view.findViewById(j.ᐧᐝ);
        ᐝ();
        this.ʽ = (TextView) view.findViewById(j.ʻ);
        this.ॱˊ = (ImageView) view.findViewById(j.ᐧʻ);
        this.ͺ = (RelativeLayout) view.findViewById(j.ʳˊ);
        this.ॱᐝ = (ExpandableLayout) view.findViewById(j.ꓸˏ);
        this.ॱˎ = view.findViewById(j.ॱᐩ);
        ʽ(view);
        return this;
    }

    public void ˏ(ExpandableLayout expandableLayout) {
        this.ॱᐝ = expandableLayout;
    }

    public void w_() {
        if (TextUtils.isEmpty(this.ˊᐝ.ॱˑ())) {
            eqx.ˏ(this.ʽॱ, this.ˊᐝ.ॱˌ(), "app_default_icon");
        } else {
            eqx.ॱ(this.ʽॱ, this.ˊᐝ.ॱˑ(), "app_default_icon");
        }
    }

    protected int ˎ() {
        int ॱˎ = eib.ॱˎ();
        int ॱ = azb.ॱ(ʼॱ().getContext());
        if (ॱˎ == 0) {
            ॱˎ = 1;
        }
        return ॱ / ॱˎ;
    }

    protected int ˊ() {
        return azb.ˊ(this.ˊˋ.getContext());
    }

    protected int ˋ() {
        return azb.ˏ(this.ˊˋ.getContext());
    }

    public NormalCardBean ʻ() {
        if (this.ˊᐝ != null) {
            return (NormalCardBean) this.ˊᐝ;
        }
        return null;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        NormalCardBean normalCardBean = (NormalCardBean) cardBean;
        this.ˑ = normalCardBean.ᶥ();
        this.ˏˏ = normalCardBean.ꓸ();
        if (this.ˎˎ != -1) {
            this.ˎˎ = djh.ˎ().ˋ(normalCardBean.ͺˏ());
        }
        if (!ˊᐝ() || ॱˊ()) {
            this.ᐝ.setVisibility(4);
        } else {
            this.ᐝ.setVisibility(0);
            ˎ(normalCardBean, this.ᐝ);
        }
        if (this.ʿ != null) {
            if (this.ˊᐝ.v_() != null) {
                this.ʿ.setVisibility(0);
            } else {
                this.ʿ.setVisibility(4);
            }
        }
        LayoutParams layoutParams = (LayoutParams) ʼॱ().getLayoutParams();
        ˎ(normalCardBean);
        layoutParams.setMarginStart(ˊ());
        ((LayoutParams) this.ͺ.getLayoutParams()).setMarginEnd(ˋ());
        if (normalCardBean.ˋˋ() != null) {
            int ˎ = (((ˎ() - ((LayoutParams) ʽ().getLayoutParams()).width) - epv.ˋ(ʼॱ().getContext(), 16)) - ˋ()) - ((layoutParams.width + layoutParams.getMarginStart()) + epv.ˋ(ʼॱ().getContext(), 16));
            if (normalCardBean.ˋˋ().ˊ() != null) {
                ˎ -= this.ʼॱ.getResources().getDimensionPixelSize(d.ॱˉ);
            }
            if (normalCardBean.ˋˋ().ॱ() != null) {
                ˎ -= this.ʼॱ.getResources().getDimensionPixelSize(d.ॱˉ);
            }
            if (!dof.ʽ(normalCardBean.ʽॱ())) {
                ˎ -= this.ʼॱ.getResources().getDimensionPixelSize(d.ߵ);
            }
            ˊˋ().setMaxWidth(ˎ);
            ˎ(this.ʼ, normalCardBean.ˋˋ().ˊ());
            ˎ(this.ॱॱ, normalCardBean.ˋˋ().ॱ());
        }
        ॱ(normalCardBean);
        ˋ(this.ˏॱ, normalCardBean.ˋʻ());
        ˏ(normalCardBean);
    }

    private void ˎ(NormalCardBean normalCardBean) {
        LayoutParams layoutParams = (LayoutParams) this.ˋॱ.getLayoutParams();
        if (dof.ʽ(normalCardBean.ʽॱ())) {
            this.ॱˋ.setVisibility(8);
            if (this.ʻॱ != null) {
                this.ʻॱ.setVisibility(8);
            }
            layoutParams.setMarginStart(this.ʼॱ.getResources().getDimensionPixelSize(d.ˏॱ));
            return;
        }
        try {
            Object ॱ = ॱ(ʻ().ʽॱ());
            this.ʻ.setText(ॱ);
            int parseInt = Integer.parseInt(ॱ);
            String ॱ2 = eiu.ˏ().ॱ(parseInt);
            if (ॱ2 == null) {
                ˏॱ();
            } else if (this.ʻॱ != null) {
                ˋ(ॱ2, parseInt);
            }
        } catch (NumberFormatException e) {
            Logger.e("NormalCard", "getAliasName_ NumberFormatException");
            ˏॱ();
        }
    }

    private String ˏ(String str) {
        return eiu.ˏ().ॱ(Integer.parseInt(ॱ(str)));
    }

    private void ˋ(final String str, final int i) {
        eqx.ॱ(ContentManager.getInstant().getContext(), str, new eqz(this) {
            final /* synthetic */ NormalCard ˎ;

            public void ॱ(Bitmap bitmap) {
                Object ˋ = this.ˎ.ˏ(this.ˎ.ʻ().ʽॱ());
                if (!TextUtils.isEmpty(ˋ) && ˋ.contentEquals(str)) {
                    if (bitmap != null) {
                        this.ˎ.ˊ(bitmap, i);
                        return;
                    }
                    Logger.ˏ("NormalCard", "rank Image download failure:" + str);
                    this.ˎ.ˏॱ();
                }
            }
        });
    }

    private void ˊ(Bitmap bitmap, int i) {
        this.ॱˋ.setVisibility(8);
        if (this.ʻॱ != null) {
            LayoutParams layoutParams = (LayoutParams) this.ʻॱ.getLayoutParams();
            if (i > 3) {
                layoutParams.width = (int) this.ʼॱ.getResources().getDimension(d.ॱʾ);
                this.ʻॱ.setText(String.valueOf(i));
                if (erq.ˏ(erq.ˎ(bitmap))) {
                    this.ʻॱ.setTextColor(this.ʼॱ.getResources().getColor(17170443));
                } else {
                    this.ʻॱ.setTextColor(this.ʼॱ.getResources().getColor(17170444));
                }
            } else {
                layoutParams.width = (int) this.ʼॱ.getResources().getDimension(d.ﹳ);
                this.ʻॱ.setText("");
            }
            this.ʻॱ.setLayoutParams(layoutParams);
            this.ʻॱ.setVisibility(0);
            this.ʻॱ.setBackground(new BitmapDrawable(this.ʼॱ.getResources(), bitmap));
        }
        ((LayoutParams) this.ˋॱ.getLayoutParams()).setMarginStart(this.ʼॱ.getResources().getDimensionPixelSize(d.ˋ) + this.ʼॱ.getResources().getDimensionPixelSize(d.ﹳ));
    }

    private void ˏॱ() {
        this.ॱˋ.setVisibility(0);
        if (this.ʻॱ != null) {
            this.ʻॱ.setVisibility(8);
        }
        ((LayoutParams) this.ˋॱ.getLayoutParams()).setMarginStart(this.ʼॱ.getResources().getDimensionPixelSize(d.ߵ));
    }

    protected int ʼ() {
        return epv.ˊ();
    }

    private void ˎ(NormalCardBean normalCardBean, View view) {
        int ʼ = ʼ();
        int ˊ = (ˊ() + ʼ) + this.ʼॱ.getResources().getDimensionPixelSize(d.ॱˊ);
        ʼ = ((ʼ + ˋ()) + this.ʼॱ.getResources().getDimensionPixelSize(d.ˏॱ)) + this.ʼॱ.getResources().getDimensionPixelSize(d.ߵ);
        if (dof.ʽ(normalCardBean.ʽॱ())) {
            ʼ = ˊ;
        }
        azb.ʼ(view, ʼ);
        view.setVisibility(0);
    }

    protected void ᐝ() {
        azb.ʻ(this.ᐝ);
    }

    public void ˏ(NormalCardBean normalCardBean) {
        if (this.ˍ != null && this.ˋᐝ != null) {
            this.ˍ.ॱ(this.ˋᐝ, this.ॱᐝ);
            new Handler().postDelayed(new b(), 300);
        } else if (djh.ˎ().ॱ() == djh.ˎ().ˋ(normalCardBean.ͺˏ()) && !normalCardBean.ꜞ() && djh.ˎ().ˎ(normalCardBean.ͺˏ())) {
            this.ॱᐝ.removeAllViews();
            this.ॱᐝ.addView(ˏ(this.ॱᐝ));
            this.ॱᐝ.setVisibility(0);
            new Handler().postDelayed(new b(), 300);
            normalCardBean.ˎ(false);
        }
        if (!normalCardBean.ꜞ() && this.ᐝॱ != null) {
            this.ᐝॱ.ˏ();
        }
    }

    public cdr ॱॱ() {
        return this.ˍ;
    }

    public boolean ॱˊ() {
        if (this.ॱᐝ == null) {
            return false;
        }
        return this.ॱᐝ.ॱ();
    }

    private String ॱ(String str) {
        if (str.contains(".")) {
            return str.substring(0, str.indexOf("."));
        }
        return str;
    }

    public void ˏ(boolean z) {
        this.ˊॱ = z;
    }

    private boolean ˎ(ImageView imageView, String str) {
        if (imageView == null) {
            return false;
        }
        if (dni.ˏ(str)) {
            imageView.setVisibility(8);
            return false;
        }
        imageView.setVisibility(0);
        return true;
    }

    public void x_() {
        NormalCardBean normalCardBean = (NormalCardBean) this.ˊᐝ;
        SpannableString ˏ = ˏ(normalCardBean);
        if (normalCardBean.ꞌ() == 4) {
            ˋ(normalCardBean);
        } else if (normalCardBean.ꞌ() == 5) {
            ˊ(normalCardBean);
        } else if (normalCardBean.ͺ() == 1 || normalCardBean.ͺ() == 3) {
            ʽ(normalCardBean);
        } else if (this.ˉ == null || this.ʽ == null || dof.ʽ(normalCardBean.ˊ()) || dof.ʽ(normalCardBean.an_()) || ˏ != null) {
            ˏ(normalCardBean, ˏ);
        } else {
            this.ˉ.setText(normalCardBean.an_());
            this.ʽ.setVisibility(0);
            this.ʽ.setText(normalCardBean.ˊ());
        }
    }

    private void ˋ(NormalCardBean normalCardBean) {
        if (this.ˉ != null) {
            CharSequence ˊ = ˊ(normalCardBean.ʹ());
            if (!TextUtils.isEmpty(ˊ) && !TextUtils.isEmpty(normalCardBean.ﹳ())) {
                ˊ = ˊ + " · " + normalCardBean.ﹳ();
            } else if (TextUtils.isEmpty(ˊ)) {
                if (TextUtils.isEmpty(normalCardBean.ﹳ())) {
                    ˊ = normalCardBean.ˏˏ();
                } else {
                    ˊ = normalCardBean.ﹳ();
                }
            }
            this.ˉ.setText(ˊ);
        }
        if (this.ʽ != null) {
            this.ʽ.setVisibility(8);
        }
    }

    private String ˊ(String str) {
        if (!TextUtils.isEmpty(str)) {
            try {
                float floatValue = Float.valueOf(str).floatValue();
                int ceil = (int) Math.ceil((double) floatValue);
                if (floatValue < 1.0f && floatValue > 0.0f) {
                    ceil = 2;
                }
                String format = String.format(Locale.ENGLISH, "%.1f", new Object[]{Float.valueOf(floatValue)});
                return this.ʼॱ.getResources().getQuantityString(i.ˎˎ, ceil, new Object[]{format});
            } catch (NumberFormatException e) {
                Logger.ˋ("NormalCard", "NormalCardBean Float.valueOf(score) error:" + e.toString());
            }
        }
        return "";
    }

    private void ˊ(NormalCardBean normalCardBean) {
        if (this.ˉ != null) {
            this.ˉ.setText(ˊ(normalCardBean.ʹ()));
        }
        if (this.ʽ != null) {
            this.ʽ.setVisibility(8);
        }
    }

    private void ˏ(NormalCardBean normalCardBean, SpannableString spannableString) {
        if (this.ˉ != null) {
            if (spannableString != null) {
                this.ˉ.setText(spannableString);
            } else {
                this.ˉ.setText(normalCardBean.ˏˏ());
            }
        }
        if (this.ʽ != null) {
            this.ʽ.setVisibility(8);
        }
    }

    private void ʽ(@NonNull NormalCardBean normalCardBean) {
        if (this.ˉ != null) {
            if (normalCardBean.ॱʾ()) {
                this.ˉ.setText(normalCardBean.showDetailUrl_);
            } else {
                this.ˉ.setText(normalCardBean.ॱˎ());
            }
        }
        if (this.ʽ != null) {
            this.ʽ.setVisibility(8);
        }
    }

    protected void ॱ(NormalCardBean normalCardBean) {
        if (normalCardBean.ٴ() != 0) {
            String ՙ = normalCardBean.ՙ();
            if (dof.ˋ(ՙ)) {
                this.ॱˊ.setVisibility(8);
            } else {
                this.ॱˊ.setVisibility(0);
                eqx.ˎ(this.ॱˊ, ՙ);
            }
            CharSequence ߴ = normalCardBean.ߴ();
            if (dof.ˋ(ߴ)) {
                this.ˋ.setVisibility(4);
            } else {
                this.ˋ.setText(ߴ);
                this.ˋ.setVisibility(0);
            }
        } else {
            this.ॱˊ.setVisibility(8);
            if (dof.ʽ(normalCardBean.ˎͺ())) {
                this.ˋ.setVisibility(4);
            } else {
                this.ˋ.setText(normalCardBean.ˎͺ());
                this.ˋ.setVisibility(0);
            }
        }
        if (normalCardBean.ʽ() != 0) {
            this.ˋ.setText(DateUtils.formatDateTime(this.ʼॱ, normalCardBean.ʽ(), 16) + HwAccountConstants.BLANK + this.ˋ.getText().toString());
        }
    }

    public SpannableString ˎ(BaseDistCardBean baseDistCardBean, SpannableString spannableString) {
        if (baseDistCardBean == null || baseDistCardBean.ˏˏ() == null) {
            return null;
        }
        return SpannableString.valueOf(baseDistCardBean.ˏˏ());
    }

    public void ˏ(cig o_cig) {
        this.ᐝॱ = o_cig;
    }

    public void ᐝ(int i) {
        this.ˎˎ = i;
        if (this.ˊᐝ != null) {
            djh.ˎ().ॱ(((NormalCardBean) this.ˊᐝ).ͺˏ(), i);
        }
    }

    public void ॱ(chy o_chy) {
        this.ˋˋ = o_chy;
        ˋॱ();
        ˎ(this.ॱˎ, o_chy);
    }

    protected void ˎ(View view, final chy o_chy) {
        if (o_chy != null) {
            this.ॱˎ.setOnClickListener(new evx(this) {
                final /* synthetic */ NormalCard ˏ;

                public void ˋ(View view) {
                    o_chy.ˏ(0, this.ˏ);
                }
            });
        }
    }

    protected void ˋॱ() {
        ʽ().setDownloadListener(new cki(this) {
            final /* synthetic */ NormalCard ॱ;

            {
                this.ॱ = r1;
            }

            public void ˋ() {
                if (this.ॱ.ˊᐝ instanceof NormalCardBean) {
                    NormalCardBean normalCardBean = (NormalCardBean) this.ॱ.ˊᐝ;
                    if (normalCardBean.ㆍ() != null) {
                        cvt ˎ = cfv.ˎ(normalCardBean.ㆍ(), null, 0, 1);
                        ˎ.setServiceType_(this.ॱ.ˏˎ);
                        ˎ.ˏॱ(this.ॱ.ˏ(this.ॱ.ˋˋ.ˎ(((NormalCardBean) this.ॱ.ˊᐝ).ͺˏ(), this.ॱ.ˊᐝ.ॱˉ())));
                        this.ॱ.ˌ = new e(this.ॱ.ᐝॱ);
                        cfw.ˎ(ˎ, this.ॱ.ˌ);
                    }
                }
            }
        });
    }

    private View ˏ(ViewGroup viewGroup) {
        this.ˍ = (cdr) cib.ˋ(this.ʼॱ, ((Layout) this.ˑ.ʻॱ().get(0)).ॱ());
        if (this.ˍ != null) {
            return ˋ(this.ˍ, viewGroup);
        }
        Logger.ˋ("NormalCard", "createItemView, node == null");
        return new View(this.ʼॱ);
    }

    private View ˋ(cie o_cie, ViewGroup viewGroup) {
        View ˊ = o_cie.ˊ(LayoutInflater.from(this.ʼॱ), null);
        if (o_cie.ˊ(ˊ, viewGroup)) {
            o_cie.ˋ(this.ˋˋ);
            chi o_chi = new chi();
            cia o_cia = new cia(viewGroup.getContext());
            o_chi.ॱ(o_cia, this.ˏˏ, this.ˑ, true);
            this.ˋᐝ = o_cia.ˏ(0);
            o_cie.ॱ(this.ˋᐝ, viewGroup);
        }
        return ˊ;
    }

    public boolean ˋ(TextView textView, String str) {
        if (textView == null) {
            return false;
        }
        if (this.ˊᐝ instanceof BaseCardBean) {
            BaseCardBean baseCardBean = (BaseCardBean) this.ˊᐝ;
            if (TextUtils.isEmpty(str) || baseCardBean.ॱʾ()) {
                textView.setVisibility(8);
                return false;
            }
        }
        return super.ˋ(textView, str);
    }
}
